package com.springboot.onlinemusicserver.controller;

import com.springboot.onlinemusicserver.model.Music;
import com.springboot.onlinemusicserver.service.MusicService;
import com.springboot.onlinemusicserver.service.UserService;
import com.springboot.onlinemusicserver.utils.common.Result;
import com.springboot.onlinemusicserver.utils.req.GetMusicParam;
import com.springboot.onlinemusicserver.utils.req.UserLoginParam;
import com.springboot.onlinemusicserver.utils.req.UserRegisterParam;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-18
 * Time: 19:02
 */
@RestController
@RequestMapping("/music")
public class MusicController {

    @Resource
    private MusicService musicService;

    // 音乐文件上传
    @PostMapping("upload")
    public Result<Boolean> upload(String singer,
                                  @RequestParam("file") MultipartFile file,
                                  HttpServletRequest request) {
        return musicService.upload(singer, file, request);
    }

    // 获取音乐
    @GetMapping("/get")
    public ResponseEntity<byte[]> getMusic(String path) {
        // path=zhangsan/陈势安 - 天后.mp3
        return musicService.getMusic(path);
    }

    // 删除单个音乐
    @PutMapping("/delete")
    public Result<Boolean> deleteMusic(Long musicId) {
        return musicService.deleteMusic(musicId);
    }

    // 批量删除
    @PutMapping("/deleteBatch")
    public Result<Boolean> deleteBatchMusic(@RequestParam("musicIds") List<Long> musicIds) {
        return musicService.deleteBatchMusic(musicIds);
    }

    // 查询音乐
    @GetMapping("/findMusic")
    public Result<List<Music>> selectMusicList(String selectName) {
        return musicService.selectMusicList(selectName);
    }
}
